#!/usr/bin/env python
#coding:utf-8
#autor:Qiweiwei

import shlex
import subprocess
host =['www.baidu.com','192.168.130.000']
def ping(ip):
    res = ''
    for host in ip:
        #print host
        cmd = "ping -n 1 %s" %(host)
        #print cmd
        args = shlex.split(cmd)
        try:
            subprocess.check_call(args,stdout=subprocess.PIPE, stderr=subprocess.PIPE)
            res += "The server %s is up !\n" %(host)
        except:
            res += "Failed to get ping %s!"%(host)
    return res
if __name__=='__main__':
        p = ping(host)
        print p
# try:
# 	subprocess.check_call(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# 	print "baidu server is up!"
# except subprocess.CalledProcessError:
# 	print "Failed to get ping."